<template>
      <div class="app-container">
        <el-form ref="form" :model="form" :rules="formRules" label-width="120px" size="medium">
            <el-form-item label="员工工号" prop="jobNumber" >
                <el-input v-model="form.jobNumber" style="width:300px" />
            </el-form-item>
            <el-form-item label="补卡时间" prop="date">
                <el-date-picker v-model="form.date" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width:300px" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('form')">添加</el-button>
                <el-button type="primary" @click="resetForm('form')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { saveUserClockRecord } from '../../api/reClockIn'

export default {
    name: 'add_reclockIn',
    data() {
        return {
            form: {
                jobNumber: '',          //员工工号
                date: ''                //补卡时间
            },
            formRules: {
                jobNumber: [
                    { required: true, message: '请输入员工工号', trigger: 'blur' }
                ],
                date: [
                    { required: true, message: '请选择补卡时间', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        // 对表单进行重置
        resetForm(formItem) {
            this.$refs[formItem].resetFields()
        },
        // 提交表单之前先进行验证
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.submit()
                } else {
                    return false
                }
            })
        },
        // 提交机台表单信息
        async submit() {
          let query = Object.assign({},this.form)
          const data = await saveUserClockRecord(query)
          const errMsg = data.msg
          if(data.code == '1') {
            this.$message({
              showClose: true,
              message: errMsg,
              type: 'success'
            })
          } else {  
            this.$message({
              showClose: true,
              message: errMsg,
              type: 'warning'
            })
          }
        }
    }
}
</script>

<style>

</style>